<?php
/**
 * Created by PhpStorm.
 * User: gyccvvh
 * Date: 2018-07-13
 * Time: 17:45
 */

namespace app\merchant\service;


use app\common\service\Service;
use think\Loader;

class MerPay extends Service{
    protected $pay_model = null;
    public function __construct(){
        parent::__construct();
        $this->pay_model = Loader::model('mer_pay');
    }

    public function getBy($mer_id,$type) {
        $pay = $this->pay_model->where("mer_id",$mer_id)->where("type",$type)
           ->find();
        if($pay) {
            return $this->ret->setCode(\app\merchant\define\Merchant::$Code_Mer_Success)
                ->setData("one", $pay->toArray());
        }else {
            return $this->ret->setCode(\app\merchant\define\Merchant::$Code_Mer_Error)
                ->setMsg(\app\merchant\define\Merchant::$Msg_Mer_404);
        }
    }

    public function saveMerPay($_post, $id){
        $res = $this->pay_model->save($_post,["id" => $id]);
        if($res) {
            return $this->ret->setCode(\app\merchant\define\Merchant::$Code_Mer_Success)
                ->setMsg(\app\merchant\define\Merchant::$Msg_Mer_Success);
        }else {
            return $this->ret->setCode(\app\merchant\define\Merchant::$Code_Mer_Error)
                ->setMsg(\app\merchant\define\Merchant::$Msg_Mer_Error);
        }
    }

    public function insertMerPay($_post){
        $res = $this->pay_model->data($_post)->save();
        if($res) {
            return $this->ret->setCode(\app\merchant\define\Merchant::$Code_Mer_Success)
                ->setMsg(\app\merchant\define\Merchant::$Msg_Mer_Success);
        }else {
            return $this->ret->setCode(\app\merchant\define\Merchant::$Code_Mer_Error)
                ->setMsg(\app\merchant\define\Merchant::$Msg_Mer_Error);
        }
    }
}